{{- $prefix := "static" }}
{{- if .Values.nodeManager.internal.capsControllerManagerEnabled }}
{{- $provider := "static" }}
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
  name: {{ $prefix }}
  namespace: d8-cloud-instance-manager
  {{- include "helm_lib_module_labels" (list . (dict "app" "caps-controller-manager")) | nindent 2 }}
#  annotations:
#    cluster.x-k8s.io/paused: "true"
# A finalizer has been added to prevent cascading removing of all capi resources after deleting the cluster resource.
  finalizers:
    - deckhouse.io/capi-controller-manager
spec:
  clusterNetwork:
    pods:
      cidrBlocks:
        - {{ .Values.global.clusterConfiguration.podSubnetCIDR }}
    services:
      cidrBlocks:
        - {{ .Values.global.clusterConfiguration.serviceSubnetCIDR }}
    serviceDomain: {{ .Values.global.clusterConfiguration.clusterDomain }}
  infrastructureRef:
    apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
    kind: StaticCluster
    namespace: d8-cloud-instance-manager
    name: {{ $prefix }}
  controlPlaneRef:
    apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
    kind: DeckhouseControlPlane
    namespace: d8-cloud-instance-manager
    name: {{ $prefix }}-control-plane
---
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: StaticCluster
metadata:
  namespace: d8-cloud-instance-manager
  name: {{ $prefix }}
  {{- include "helm_lib_module_labels" (list . (dict "app" "caps-controller-manager")) | nindent 2 }}
---
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: DeckhouseControlPlane
metadata:
  namespace: d8-cloud-instance-manager
  name: {{ $prefix }}-control-plane
  {{- include "helm_lib_module_labels" (list . (dict "app" "caps-controller-manager")) | nindent 2 }}
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineHealthCheck
metadata:
  namespace: d8-cloud-instance-manager
  name: {{ $prefix }}-machine-health-check
  {{- include "helm_lib_module_labels" (list . (dict "app" "caps-controller-manager")) | nindent 2 }}
spec:
  clusterName: {{ $provider }}
  nodeStartupTimeout: 20m
  selector:
    matchLabels:
      cluster.x-k8s.io/cluster-name: {{ $provider }}
  # unhealthyConditions is required, but we don't need to check any conditions for nodes managed by CAPS, so we set a very long timeout (100 years).
  unhealthyConditions:
    - type: Ready
      status: Unknown
      timeout: 876000h
{{- end }}
